package com.wuchao.utils;

import org.springframework.core.convert.converter.Converter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author wuchao66
 * @Date 2023/10/20 14:39
 * @PackageName:com.wuchao.utils
 * @ClassName: StringToDateConvter
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
public class StringToDateConvter implements Converter<String, Date> {
    //构造入参
    private String format;//咱们自定想要今天那种格式
    public StringToDateConvter( String format){
        this.format=format;
    }
    @Override
    public Date convert(String s) {//s是传入的时间字符串
        DateFormat df=new SimpleDateFormat(this.format);
        Date date=null;
        try {
            date= df.parse(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }
}
